<?php

namespace app\live\controller;

use app\common\controller\Adminbase;
use app\model\Talent as TalentModel;

class Expert extends Adminbase
{
    public function index()
    {
        $model = 'Talent';

        if ($this->request->isAjax()) {
            $map      = $this->buildParamsMap();
            $page     = input('page') ? input('page') : 1;
            $pageSize = input('limit') ? input('limit') : 20;

            $list   = TalentModel::where($map)
                ->field('*')
                ->withAttr('bind_time', function ($value) {
                    return $value ? date('Y-m-d H:i:s', $value) : '';
                })
                ->page($page, $pageSize)
                ->order('bind_time', 'desc')
                ->order('id', 'asc')
                ->select();
            $total  = TalentModel::where($map)->count();
            $result = ["code" => 0, "count" => $total, "data" => $list];
            return json($result);
        }

        //生成列表数据
        $builder = new \app\common\controller\ListBuilder();
        $builder
            ->setAddBtn(false)
            ->setDelAllBtn(false)
            ->setDataUrl()
            ->setFormUrl('form')
            ->setLimit()
            ->setModel($model)
            ->addTableCheckBox()
            ->setSwitchTpl('amplifyTpl', 'talent_head_img')
            ->addTableColumn('id', 'ID', null, null, true)
            ->addTableColumn('talent_appid', '达人ID')
            ->addTableColumn('talent_nickname', '达人昵称')
            ->addTableColumn('talent_head_img', '达人头像', null, '#amplifyTpl')
            ->addTableColumn('bind_time', '绑定时间')
            ->returnForm();

        $this->assign('module', 'app');
        return $this->fetch('admin@common/lists');
    }
}
